﻿
namespace n_ExampleForm
{
using System;
using System.Drawing;
using System.Windows.Forms;

using n_GUIset;
using n_MyFileObject;
using n_HardModule;
using n_UIModule;
using n_MyObject;
using n_GUIcoder;
using n_ExMesPanel;

/// <summary>
/// Description of WorkForm.
/// </summary>
public partial class ExampleForm : Form
{
	public ExMesPanel GPanel;
	
	const int GWidth = 900;
	const int MesWidth = GWidth - 20 - 20;
	
	SolidBrush backb;
	
	//主窗口
	public ExampleForm()
	{
		InitializeComponent();
		
		//添加图形编程界面
		GPanel = new ExMesPanel();
		
		//GPanel.Location = new Point( 0, 0 );
		GPanel.Visible = true;
		this.panel2.Controls.Add( GPanel );
		
		backb = new SolidBrush( Color.WhiteSmoke );
		
		GPanel.LibList = n_OS.VIO.OpenTextFile( n_OS.OS.SystemRoot + "example\\example.txt" ).Split( '\n' );
	}
	
	//设置打开方式检查位
	public void ShowOpenCheck()
	{
		radioButtonNew.Visible = true;
		radioButtonClose.Visible = true;
	}
	
	//重新设置示例列表
	public void ResetLib( string lib, string PrePath )
	{
		GPanel.LibList = lib.Split( '\n' );
		GPanel.PrePath = PrePath;
	}
	
	//运行
	public void Run( MyFileObject cm )
	{
		Run( cm.MacroFilePath.Remove( 0, n_OS.OS.ModuleLibPath.Length ) );
	}
	
	//运行
	public void Run( string flag )
	{
		GPanel.SetMes( flag );
		
		if( GPanel.ModList != null ) {
			this.Text = "模块用法示例 (一共" + GPanel.ModList.Length + "个示例)";
		}
		else {
			this.Text = "此模块暂无示例";
		}
		
		GPanel.StartY = 0;
		
		//TextHeight = SearchHeight( MM, MesWidth );
		GPanel.GWidth = this.Width;
		
		GPanel.Invalidate();
		this.Visible = true;
		
		GPanel.Focus();
	}
	
	//窗体关闭事件
	void UnitLibFormFormClosing(object sender, FormClosingEventArgs e)
	{
		e.Cancel = true;
		this.Visible = false;
	}
	
	void DescriptionFormSizeChanged(object sender, EventArgs e)
	{
		if( GPanel != null ) {
			GPanel.GWidth = this.Width;
			GPanel.Invalidate();
		}
	}
	
	void ButtonOpenLibFolderClick(object sender, EventArgs e)
	{
		string fileToSelect = n_OS.OS.SystemRoot + "example\\应用类示例";
        string args = string.Format("/Select, {0}", fileToSelect);
        System.Diagnostics.Process.Start( new System.Diagnostics.ProcessStartInfo("Explorer.exe", args ) );
	}
	
	void ButtonJiMuClick(object sender, EventArgs e)
	{
		string fileToSelect = n_OS.OS.SystemRoot + "arduino-ext\\2路马达扩展";
        string args = string.Format("/Select, {0}", fileToSelect);
        System.Diagnostics.Process.Start( new System.Diagnostics.ProcessStartInfo("Explorer.exe", args ) );
	}
	
	void RadioButtonNewCheckedChanged(object sender, EventArgs e)
	{
		GPanel.NewFormOpen = radioButtonNew.Checked;
	}
	
	void ButtonGameClick(object sender, EventArgs e)
	{
		string fileToSelect = n_OS.OS.SystemRoot + "example\\动画游戏类\\1.1 基础";
        string args = string.Format("/Select, {0}", fileToSelect);
        System.Diagnostics.Process.Start( new System.Diagnostics.ProcessStartInfo("Explorer.exe", args ) );
	}
	
	void ButtonCircuitClick(object sender, EventArgs e)
	{
		string fileToSelect = n_OS.OS.SystemRoot + "example\\电路仿真\\2逻辑门电路";
        string args = string.Format("/Select, {0}", fileToSelect);
        System.Diagnostics.Process.Start( new System.Diagnostics.ProcessStartInfo("Explorer.exe", args ) );
	}
}
}



